package com.mical.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/actuator")
public class ThreadPoolController {


    @Autowired
     private ThreadPoolTaskExecutor executor;


    public ThreadPoolController(  ThreadPoolTaskExecutor executor) {
        this.executor = executor;
    }

    @GetMapping("/thread-pool")
    public Map<String, Object> getThreadPoolInfo() {
        return Map.of(
                "activeCount", executor.getActiveCount(),
                "poolSize", executor.getPoolSize(),
                "corePoolSize", executor.getCorePoolSize(),
                "maxPoolSize", executor.getMaxPoolSize(),
                "queueSize", executor.getThreadPoolExecutor().getQueue().size()
        );
    }
}